﻿using System.Web.UI;

namespace Web
{
    public class BaseMasterPage : MasterPage
    {
        public BaseMasterPage()
        {
            IoC.StructureMap.BuildUp(this);
        }

        public Control BaseFindControl(string id)
        {
            return base.FindControl(id);
        }

        public override Control FindControl(string id)
        {
            return FindControlRecursive(id, this);
        }

        private Control FindControlRecursive(string id, BaseMasterPage master)
        {
            if (master == null) return null;

            Control ctl = master.BaseFindControl(id);

            if (ctl == null)
            {
                return FindControlRecursive(id, (BaseMasterPage)master.Master);
            }

            return ctl;
        } 
    }
}